package cn.gxa.edu_adm.dao.impl;

import cn.gxa.edu_adm.bean.Classes;
import cn.gxa.edu_adm.dao.ClassesDao;
import cn.gxa.edu_adm.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ArrayListHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class ClassesDaoImpl  implements ClassesDao {
    @Override
    public List<Classes> findAll() {
        String  sql="select  *  from  classes";
        QueryRunner queryRunner=new QueryRunner(DruidUtils.getDruidDataSource());
        try {
            return queryRunner.query(sql,new BeanListHandler<>(Classes.class));
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
/*
* List<Object[]>
    	6
软件1班	3
软件2班	4
数媒1班	3
    Map
    * put  为分班     6
    * put  软件1班   3
* */

    public  List<Object[]>  test(){
        String   sql="select   c.claName,count(s.stuId)  from student s left join classes  c on s.claId=c.claId GROUP BY  c.claId";
        QueryRunner queryRunner=new QueryRunner(DruidUtils.getDruidDataSource());

        try {
            return  queryRunner.query(sql,new ArrayListHandler());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return   null;
    }
}
